package com.ewzj.bigdata.mvp.model

import com.ewzj.bigdata.app.config.netmodel.CommonService
import com.ewzj.bigdata.app.utils.RxUtils
import com.ewzj.bigdata.mvp.contract.HomeFragmentContract
import com.ewzj.bigdata.mvp.contract.MineFragmentContract
import com.ewzj.bigdata.mvp.model.bean.UserBean
import com.ewzj.bigdata.mvp.model.rspbean.BaseData
import com.google.gson.Gson
import com.jess.arms.integration.IRepositoryManager
import com.jess.arms.mvp.BaseModel
import com.jess.arms.utils.UiUtils
import io.reactivex.Observable
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File
import javax.inject.Inject

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class MineFragmentModel @Inject constructor(val mGson:Gson,repositoryManager: IRepositoryManager):BaseModel(repositoryManager),MineFragmentContract.Model {
    val service=repositoryManager.obtainRetrofitService(CommonService::class.java)
    override fun loadUserInfo(): Observable<BaseData<UserBean>> {
        return service.userInfo()
    }

    override fun upLoadPic(file: File): Observable<BaseData<List<String>>> {
        val builder = MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("mode", "BG")
        //表单类型;
        val imageBody = RequestBody.create(MediaType.parse("multipart/form-data"), file)
        builder.addFormDataPart("filed1", file.name, imageBody)//imgfile 后台接收图片流的参数名
        val parts = builder.build().parts()
        return service.uploadPic(parts)
    }
}